import {
  requestCategoryList,
  requestBannerList,
  requestFloorList,
} from "@/api";

const state = {
  categoryList: [],
  bannerList: [],
  floorList: [],
};

const mutations = {
  // 三级列表数据
  SET_CARTGORYLIST_STATE(state, value) {
    //接收两个参数 第一个是state 当前值 第二个是 commit改变的值
    state.categoryList = value;
  },
  // banner图片列表
  SET_BANNER_STATE(state, value) {
    state.bannerList = value;
  },
  // floor列表
  SET_FLOOR_STATE(state, value) {
    state.floorList = value;
  },
};

const actions = {
  // 异步发送三级列表请求
  async getCategoryList({ commit }) {
    const result = await requestCategoryList();
    // 用commit 改变mutations
    commit("SET_CARTGORYLIST_STATE", result);
  },
  // 请求banner
  async getBannerList({ commit }) {
    const result = await requestBannerList();
    commit("SET_BANNER_STATE", result);
  },
  // 请求floor
  async getFloorList({ commit }) {
    const result = await requestFloorList();
    commit("SET_FLOOR_STATE", result);
  },
};

export default {
  namespaced: true, // 开启命名空间
  state,
  mutations,
  actions,
};
